package com.xingchi.tornado.dict.enums;

import com.xingchi.tornado.basic.BaseEnum;
import lombok.Getter;

import java.util.Arrays;

/**
 * 字典数据存储类型
 *
 * @author xingchi
 * @date 2024/5/19 21:07
 */
@Getter
public enum DictStorageTypeEnum implements BaseEnum {

    /**
     * 字典数据存储类型
     */
    IN_MEMORY(1, "内存存储", true),
    JDBC(2, "数据库", true),
    REDIS(3, "redis存储", false),

    ;
    private final Integer code;
    private final String description;
    private final boolean isVisible;

    DictStorageTypeEnum(Integer code, String description, boolean isVisible) {
        this.code = code;
        this.description = description;
        this.isVisible = isVisible;
    }

    public static DictStorageTypeEnum getInstance(Integer code) {
        return Arrays.stream(DictStorageTypeEnum.values())
                .filter(dictStorageTypeEnum -> dictStorageTypeEnum.isType(code))
                .findFirst()
                .orElse(null);
    }

    public static DictStorageTypeEnum getInstanceOrDefault(Integer code, DictStorageTypeEnum defaultEnum) {
        return Arrays.stream(DictStorageTypeEnum.values())
                .filter(dictStorageTypeEnum -> dictStorageTypeEnum.isType(code))
                .findFirst()
                .orElse(defaultEnum);
    }

}
